package com.whz.method;

import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;

import java.util.*;

/**
 * @Author: sinosoft
 * @Description: 奶酪服务类
 * 可能返回零长度集合
 * @Date: Create in 11:17 2021/5/24
 * @Modified By:
 */
@Slf4j
public class CheeseService {
    /**
     * 避免重复分配空集合空间
     */
    private static final Cheese[] EMPTY_CHEESE_ARRAY = new Cheese[0];


    private static Integer i;
    public static void main(String[] args) {
//        int compare = naturalOrder.compare(new Integer(42), new Integer(42));
//        log.info("compare: {}", compare);
//        Comparator.naturalOrder();
        /**
         * 当在一项操作中混合使用基本类型和装箱基本类型时，装箱基本类型就会自动拆箱
         * 如果null对象引用被自动拆箱 就会抛出一个NullPointerException异常
         */
        if(i == 42) {
            log.info("不相等");
        }

    }
    public Collection<Cheese> getCheeseList() {
        List<Cheese> cheeseList = Lists.newArrayListWithCapacity(10);
        for (int i = 0; i < 10; i++) {
            cheeseList.add(Cheese.make(i));
        }
        return Collections.unmodifiableList(cheeseList);
    }

    public Cheese[] getCheeseArr() {
        List<Cheese> cheeseList = Lists.newArrayListWithCapacity(0);
        for (int i = 0; i < 10; i++) {
            cheeseList.add(Cheese.make(i));
        }
        return cheeseList.toArray(EMPTY_CHEESE_ARRAY);
    }
}
